package com.etc.controller;

import com.etc.pojo.Video;
import com.etc.service.VideoService;
import com.github.pagehelper.PageInfo;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

//@WebServlet("/VideoController")
@Controller
@RequestMapping("/exercise")
public class VideoController {
    Logger logger = Logger.getLogger(VideoController.class);
    @Autowired
    private VideoService service;



    @RequestMapping("/queryVideoAll")
    public String queryVideoAll(Model model) {
        List<Video> videoList = service.getQueryVideos();
        model.addAttribute("list", videoList);
        return "video";
    }

    @RequestMapping("/deleteVideo")
    public String deleteVideoId(int videoId) {
        service.getDeleteVideo(videoId);
        return "redirect:/exercise/queryVideoAll";
    }

    @RequestMapping("/toUpdate")
    public String toUpdatePer(int videoId,Model model) {
       Video video = service.getqueryVideosType(videoId);
        System.out.println(video);
        model.addAttribute("video",video);
        return "updateVideo";
    }

    @RequestMapping("/updateVideo")
    public String updateVideoper(Video video) {
        System.out.println(1111);
        System.out.println(video);
        service.getUpdateVideo(video);
        return "redirect:/exercise/queryVideoAll";
    }

    @RequestMapping("/toAddVideo")
    public String toAddPer() {
        return "insertVideo";
    }

    @RequestMapping("/addVideo")
    public String AddVideoPer(Video video) {
        service.getaddVideo(video);
        return "redirect:/exercise/queryVideoAll";
    }
    @ResponseBody
    @RequestMapping("/queryAllVideo")
    public PageInfo<Video> queryAllVideo(@RequestParam(value = "pageNum",defaultValue = "1") int pageNum, @RequestParam(value = "pageSize",defaultValue = "5") int pageSize){
        PageInfo<Video> info = service.getQueryVideo(pageNum, pageSize);
        System.out.println(info);
        return info;
    }
}




